Customize the features and design of the Algolia Autocomplete menu for Adobe Commerce and Magento Open Source.
vendor/algolia/algoliasearch-magento-2/view/frontend/web
.
As a starting point for your customizations, you can download a template.
Autocomplete option | Description |
---|---|
placeholder | Text shown in the search box before users type |
debug | If true, the Autocomplete menu stays open even if you click outside it |
openOnFocus | If true, the Autocomplete menu displays as soon as a user clicks on the search input field |
afterAutocompleteOptions
hook.
For example:
Autocomplete source | Description |
---|---|
products | Products from your catalog |
categories | Product categories |
pages | Pages |
suggestions | Suggestions from popular searches |
additional_sections | Additional sections you configured in the Magento Admin |
afterAutocompleteSources
hook.
The callback function for afterAutocompleteSources
must return the complete sources array.
For example:
afterAutocompleteSources
accepts two parameters:
Parameter | Type | Description |
---|---|---|
sources | Array of sources | Data for autocomplete items |
searchClient | Search client | Initialized Algolia search client |
algoliaAnalytics
, use RequireJS to define them as dependency for your algoliaHooks
implementation.
sources
array is a JavaScript object with the following properties:
Property | Type | Required | Description |
---|---|---|---|
sourceID | String | Required | Unique identifier for your source. Use a sourceID of a builtin source to override it. |
indexName | String | Required | Index name. It’s records will be searchable in the autocomplete menu. To reference a Magento store index, use algoliaConfig.indexName as prefix. |
templates | Autocomplete templates | item template is required | Templates for rendering items (item ), no-results display (noResults ), a header (header ), and footer (footer ). |
getItemUrl | function | Function to return the URL for an item for keyboard navigation. | |
transformResponse | function | Function to transform the response from the Algolia API before turning it to Autocomplete items. For more information, see getAlgoliaResults . | |
options | Search parameters | Add or override Algolia search parameters, such as the hitsPerPage parameter. |
afterAutocompletePlugins
hook.
For example, to add recent searches to your autocomplete menu:
Template file | Description |
---|---|
autocomplete.phtml | Autocomplete menu |
products.js | Products |
categories.js | Categories |
pages.js | Pages |
suggestions.js | Search suggestions |
additional-section.js | Additional sections |
web/js/template/autocomplete/
directory.
requirejs-config.js
file in your theme or custom module:
getItemHtml
function, leaving other aspects unchanged.
getColorHtml
or getCategoriesHtml
without editing the getItemHtml
function.
mage/utils/wrapper
JavaScript module.
Wrappers let you invoke the original template function and include its output with the _super
method.
The following example overrides the getHeaderHtml
method of the Autocomplete category hit template:
Algolia_CustomAlgolia
extension which installs a set of starter templates for your customizations.
For more information see Create a custom extension.
topSearch
block of the template.
If you’re using a custom theme without the topSearch
block,
update the DOM selector for the search input.
Go to Stores > Algolia Search > Autocomplete Menu in the Magento Admin, and change the Search Input Container Selector setting:
before_body_end
block, ensure the theme renders this block.